package com.uestc.admin;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.uestc.coprocessor.userfeedback.UserFeedbackClient;
import com.uestc.hbase.MTable;
import com.uestc.util.Log;

/**
 * 
 * @author lenovo
 *
 */
public class UserFeedBackAdmin implements AdminBase {

	private String columnName = "userFeedBackColumns";
	private String tableName = "userfeedback";

	@Override
	public String getInfo(int page, int limit, HttpServletRequest request) throws Throwable {
		return this.getDetailInfo(tableName, columnName, Arrays.asList(new String[] { "info" }), page, limit, request);
	}

	@Override
	public String getColumnName() {
		return columnName;
	}

	@Override
	public String getTableName() {
		return tableName;
	}

	@Override
	public String getInfoWithCondition(int page, int limit, HashMap<String, String> conditions,
			HttpServletRequest request) throws Throwable {
		return this.getDetailInfo(tableName, this.columnName, Arrays.asList(new String[] { "info" }), page, limit,
				request, "info", conditions, MTable.FILTER_TYPE.PREFIX_FILTER);
	}

	public String getFeedbackStatistics(String type) throws IOException {
		UserFeedbackClient client = new UserFeedbackClient();
		MTable mTable = null;
		String result = null;
		try {
			mTable = new MTable(tableName);
			result = client.getCallback(mTable.getTable(), type);
		} catch (Throwable e) {
			Log.logException(e);
		} finally {
			if (mTable != null)
				mTable.close();
		}
		return result;
	}

	@Override
	public String getDateColumnName() {
		return "date";
	}
}
